package game.data.recipeskill;

import java.util.ArrayList;
import java.util.Random;

import game.conflict.ConflictModel;
import game.conflict.Data;
import game.element.Material;
import game.element.NormalSkill;
import game.element.Seasoning;

public class chenyucanxue extends NormalSkill{
	int time=-1;
	@Override
	public boolean check(ConflictModel model) {
		if(time==-1)
			time=model.getTimes();
	
		if(model.getGamestate()==Data.fighting&&model.isSuccess()&&(model.getTimes()-time)%2!=0)
			return true;
		// TODO Auto-generated method stub
		return false;
	}
	
	
	@Override
	public void doing(ConflictModel model) {
		Material material;
		ArrayList<Material> matlist=new ArrayList<Material>();
		boolean x=false;
		// TODO Auto-generated method stub
		for(Material m:model.getNow_player().getMaterials()){
			if(!m.getSeasonings().isEmpty()){
				matlist.add(m);
			    x=true;
			}
		}
		
		if(x){
			Seasoning seasoning;
			material=matlist.get(new Random().nextInt(matlist.size()));
			model.getAttacked().add((seasoning=material.getSeasonings().get(new Random().nextInt(material.getSeasonings().size()))));	
			material.remove(seasoning);
		}
		else {
			material=model.getNow_player().getMaterials().get(new Random().nextInt(3));
			material.setN_taste(material.getN_taste()-1);
		}
		
	}
	
	@Override
	public boolean addMaterial(Material material) {
		// TODO Auto-generated method stub
		return super.addMaterial(material);
	}

}
